package com.hjwoo.app.views;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.hjwoo.app.R;
import com.hjwoo.app.baseviews.BaseAppCompatActivity;
import com.hjwoo.app.utils.MyTimeUtils;
import com.hjwoo.app.utils.Utils;

/**
 * Create by ：rxiaowen on 2016/8/3
 * Email：rxiaowen@sina.com
 * 获取时间段界面
 */
public class GetTimeActivity extends BaseAppCompatActivity implements View.OnClickListener{
    private static final int BTN_TEXT1 = 0;
    private static final int BTN_TEXT2 = 1;
    private static final int BTN_TEXT3 = 2;
    private static final int BTN_TEXT4 = 3;
    private static final int BTN_TEXT5 = 4;
    private static final int BTN_TEXT6 = 5;
    private static final int BTN_TEXT7 = 6;
    private static final int BTN_TEXT8 = 7;
    Button btn_time1,btn_time2,btn_time3,btn_time4,btn_time5,btn_time6,btn_time7,btn_time8,btnBack;
    Intent intent;
    TextView textHeadTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_time);
        Utils.initTitle("选择时间", GetTimeActivity.this, true);
        findViewById(R.id.btnBack).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
         initView();
        initOnClickListener();
    }

    private void initOnClickListener() {
       btn_time1.setOnClickListener(this);
       btn_time2.setOnClickListener(this);
        btn_time3.setOnClickListener(this);
        btn_time4.setOnClickListener(this);
        btn_time5.setOnClickListener(this);
        btn_time6.setOnClickListener(this);
        btn_time7.setOnClickListener(this);
        btn_time8.setOnClickListener(this);
        btnBack.setOnClickListener(this);
    }

    private void initView() {
       btnBack = (Button) findViewById(R.id.btnBack);
        btn_time1 = (Button)findViewById(R.id.btn_time1);
        btn_time2 = (Button)findViewById(R.id.btn_time2);
        btn_time3 = (Button) findViewById(R.id.btn_time3);
        btn_time4 = (Button) findViewById(R.id.btn_time4);
        btn_time5 = (Button) findViewById(R.id.btn_time5);
        btn_time6 = (Button) findViewById(R.id.btn_time6);
        btn_time7 = (Button) findViewById(R.id.btn_time7);
        btn_time8 = (Button) findViewById(R.id.btn_time8);
        textHeadTitle = (TextView) findViewById(R.id.textHeadTitle);
        textHeadTitle.setText("预约时间");
        btnBack = (Button) findViewById(R.id.btnBack);
        btnBack.setVisibility(View.VISIBLE);
    }

    @Override
    public void onClick(View v) {
        intent = new Intent(GetTimeActivity.this,AppointmentTimeActivity.class);
        switch (v.getId()){
            case R.id.btn_time1:
                String btn_text1 =  btn_time1.getText().toString();
                intent.putExtra("btn_text1",btn_text1);
                this.setResult(BTN_TEXT1, intent);
                break;
            case R.id.btn_time2:
                String btn_text2 =  btn_time2.getText().toString();
                intent.putExtra("btn_text2",btn_text2);
                this.setResult(BTN_TEXT2, intent);
                break;
            case R.id.btn_time3:
                String btn_text3 =  btn_time3.getText().toString();
                intent.putExtra("btn_text3",btn_text3);
                this.setResult(BTN_TEXT3, intent);
                break;
            case R.id.btn_time4:
                String btn_text4 =  btn_time4.getText().toString();
                intent.putExtra("btn_text4",btn_text4);
                this.setResult(BTN_TEXT4, intent);
                break;
            case R.id.btn_time5:
                String btn_text5 =  btn_time5.getText().toString();
                intent.putExtra("btn_text5",btn_text5);
                this.setResult(BTN_TEXT5, intent);
                break;
            case R.id.btn_time6:
                String btn_text6 =  btn_time6.getText().toString();
                intent.putExtra("btn_text6",btn_text6);
                this.setResult(BTN_TEXT6, intent);
                break;
            case R.id.btn_time7:
                String btn_text7 =  btn_time7.getText().toString();
                intent.putExtra("btn_text7",btn_text7);
                this.setResult(BTN_TEXT7, intent);
                break;
            case R.id.btn_time8:
                String btn_text8 =  btn_time8.getText().toString();
                intent.putExtra("btn_text8",btn_text8);
                this.setResult(BTN_TEXT8, intent);
                break;
            case R.id.btnBack:
               finish();
                break;
        }
        finish();
    }
    //监听手机返回键
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK ){
            finish();
        }
        return super.onKeyDown(keyCode, event);
    }
}
